package com.realtyManage.springboot.Utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.realtyManage.springboot.Config.WxProgramPayConfig;
import com.realtyManage.springboot.Model.Do.*;
import com.realtyManage.springboot.Model.Vo.DictionariesEntity;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import javax.persistence.Column;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class BuildTreeUtil {
    public static List<DictionariesZero> buildTreeZero(List<DictionariesZero> list, int parentId){
        List<DictionariesZero> menus= new ArrayList<DictionariesZero>();
        for (DictionariesZero menu : list) {
            int menuId = menu.getMenuId();
            int pid = Integer.valueOf(menu.getParentId());
            if (parentId == pid) {
                List<DictionariesZero> menuLists = buildTreeZero(list, menuId);
                menu.setChildMenu(menuLists);
                menus.add(menu);
            }
        }
        return menus;
    }

    public static List<Dictionaries> buildTree(List<Dictionaries> list, int parentId){
        List<Dictionaries> menus= new ArrayList<Dictionaries>();
        for (Dictionaries menu : list) {
            int menuId = menu.getMenuId();
            int pid = Integer.valueOf(menu.getParentId());
            if (parentId == pid) {
                List<Dictionaries> menuLists = buildTree(list, menuId);
                menu.setChildMenu(menuLists);
                menus.add(menu);
            }
        }
        return menus;
    }

    public static List<DictionariesOne> buildTreeOne(List<DictionariesOne> list, int parentId){
        List<DictionariesOne> menus=new ArrayList<DictionariesOne>();
        for (DictionariesOne menu : list) {
            int menuId = menu.getMenuId();
            int pid = Integer.valueOf(menu.getParentId());
            if (parentId == pid) {
                List<DictionariesOne> menuLists = buildTreeOne(list, menuId);
                menu.setChildMenu(menuLists);
                menus.add(menu);
            }
        }
        return menus;
    }

    public static List<DictionariesTwo> buildTreeTwo(List<DictionariesTwo> list, int parentId){
        List<DictionariesTwo> menus=new ArrayList<DictionariesTwo>();
        for (DictionariesTwo menu : list) {
            int menuId = menu.getMenuId();
            int pid = Integer.valueOf(menu.getParentId());
            if (parentId == pid) {
                List<DictionariesTwo> menuLists = buildTreeTwo(list, menuId);
                menu.setChildMenu(menuLists);
                menus.add(menu);
            }
        }
        return menus;
    }

    public static List<Discuss> buildTlTree(List<Discuss> list, int parentId){
        List<Discuss> menus=new ArrayList<Discuss>();
        for (Discuss menu : list) {
            int menuId = menu.getId();
            int pid = Integer.valueOf(menu.getParentId());
            if (parentId == pid) {
                List<Discuss> menuLists = buildTlTree(list, menuId);
                menu.setChildMenu(menuLists);
                menus.add(menu);
            }
        }
        return menus;
    }
}
